# -*- coding: utf-8 -*-
from Python_Structure_Algorithm.DoubleLinkedList import DoubleLinkedList


class Deque(DoubleLinkedList):

    def pop(self):
        tailnode = self.root.prev
        self.remove(tailnode)
        return tailnode.value
    def popleft(self):
        headnode = self.root.next
        self.remove(headnode)
        return headnode.value


def test_deque():
    dq = Deque()
    dq.append(0)
    dq.append(1)
    dq.append(2)
    dq.append(3)

    assert list(dq) == [0, 1, 2, 3]
    dq.appendleft(-1)
    assert list(dq) == [-1, 0, 1, 2, 3]
    assert dq.pop() == 3
    assert dq.popleft() == -1
    assert list(dq) == [0, 1, 2, ]
